package cn.gson.boot.controller;

import cn.gson.boot.model.pojos.SupplierContact;
import cn.gson.boot.model.service.SupplierContactService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/supplierContact")
public class SupplierContactController {
    @Autowired
    SupplierContactService supplierContactService;


    /**
     * 查询所有的供应商联系人
     * @return
     */
    @RequestMapping("/supplierContact-list")
    @ResponseBody
    public Map<String,Object> selectSupplierContact(Integer pageNum, Integer pageSize, String search, String type){
        Page<Object> obj = PageHelper.startPage(pageNum,pageSize);
        supplierContactService.selectSupplierContact(search,type);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",obj.getResult());
        return map;
    }

    /**
     * 查询某个供应商下有哪些联系人
     * @return
     */
    @RequestMapping("/ContactsBySupId")
    @ResponseBody
    public List<SupplierContact> ContactsBySupId(String supplierName) {
        return supplierContactService.ContactsBySupId(supplierName);
    }

    /**
     * 新增供应商联系人
     * @return
     */
    @RequestMapping("/addSupplierContact")
    @ResponseBody
    public void addSupplierContact(@RequestBody SupplierContact supplierContact) {
        System.out.println(supplierContact);
        supplierContactService.addSupplierContact(supplierContact);
    }

    /**
     * 查询需要修改的供应商联系人
     * @return
     */
    @RequestMapping("/upSupContact")
    @ResponseBody
    public List<SupplierContact> upSupContact(Integer supcontactId) {
        return supplierContactService.upSupContact(supcontactId);
    }

    /**
     * 删除供应商联系人
     * @return
     */
    @RequestMapping("/delSupContact")
    @ResponseBody
    public void delSupContact(Integer supcontactId) {
        supplierContactService.delSupContact(supcontactId);
    }
}
